package com.xxx.server.converter;


import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 日期转换
 *
 * @author daixl
 * @date 2021/3/8
 */
@Component
public class DateConverter implements Converter<String, LocalDate> {

    @Override
    public LocalDate convert(String s) {
        if (!(s == "" || s == null || s.length() == 0 || "".equals(s))) {
            try {
                return LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
